<?php include_once($_SERVER['DOCUMENT_ROOT']."/controller/common/common_setting_unit.php");         // 引入通用的设置文件 ?>
<?php include_once($_SERVER['DOCUMENT_ROOT']."/controller/common/module/head.php"); // 引入通用的头部 ?>
<?php include_once("../controller/data_static.php");                     // 当前页面的控制器 ?>



<body>

<!--//遮罩图层-->
<div class="message_layer">
    <div class="message_layer_content_box" >
        <div class="layui-icon layui-anim layui-anim-rotate layui-anim-loop" >
            &#xe63d;
        </div>
        <div  class="content_box" >程序处理中，请稍等。</div>
    </div>
</div>

<script type="text/javascript" src="/controller/common/asset/js/controller.js"></script>

<!--
增加一个载入遮罩动画，等待文件载入完毕，则取消遮罩
-->
<script>
    //search_button 点击的时候执行
    $(function(){
        $("#search_button").click(function(){
            show_message_layer()
        })
    })

    show_message_layer()

    //文件载入完毕，则执行hide_message_layer
    window.onload = function() {
        hide_message_layer();
    };

</script>







<!--顶部栏-->
<div id="topbar"> <?php include $_SERVER['DOCUMENT_ROOT'] . '/controller/common/module/topbar.php'; ?></div>

<!--容器-->
<div id="container" class="<? echo $now_extender ?>">

    <!--侧边栏-->
    <div id="sidebar"><?php include $_SERVER['DOCUMENT_ROOT'] . '/controller/common/module/sidebar.php'; ?></div>


    <div id="content">
        <?php $page_title='订单统计';?>
        <?php include ROOT_PATH_.'/controlbase/module/mod-page-title.php'; ?>





<div class="detail-box  layui-form">

<div class="detail-boxes">




    <form action="detail-statistic.php" >

        <div class="select-box">
            <div class="layui-form-item search-period">
                <label class="layui-form-label">时间段</label>

                <div class="layui-input-block">
                    <input type="text" name="greaterequal_ondate"
                           placeholder="请输入开始时间" autocomplete="off" class="layui-input laydate_date"
                           value="<?if($_REQUEST['greaterequal_ondate']){echo $_REQUEST['greaterequal_ondate'] ;} ?>" >
                    <span>-</span>
                    <input type="text" name="lessequal_ondate"
                           placeholder="请输入结束时间" autocomplete="off" class="layui-input laydate_date"
                           value="<?if($_REQUEST['lessequal_ondate']){echo $_REQUEST['lessequal_ondate'];} ?>"  >
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">学校</label>
                <div class="layui-input-block">
                    <select name="school" value="<? echo $_REQUEST['school']?>">
                        <option value="">请选择学校</option>

                        <? for($i=0;$i<count($school_list);$i++){ ?>
                            <option value="<? echo $school_list[$i]['name'] ?>"
                                <?php if($_REQUEST['school'] == $school_list[$i]['name']){echo "selected";} ?> >
                                <? echo $school_list[$i]['name'] ?>
                            </option>
                        <? } ?>
                    </select>
                </div>
            </div>



            <input type="hidden" name="now_extender" value="<?echo $_REQUEST['now_extender']?>">

            <button id="search_button" class="layui-btn  layui-btn-sm" ><i class="layui-icon">&#xe615;</i> 查找</button>
            <a class="layui-btn white layui-btn-sm" href="detail-statistic.php?now_extender=<?echo $_REQUEST['now_extender']?>" ><i class="layui-icon">&#x1006;</i> 重置</a>
            <a class="layui-btn white layui-btn-sm" target="_blank"
               href="export.php?greaterequal_ondate=<?echo $_REQUEST['greaterequal_ondate']?>&lessequal_ondate=<?echo $_REQUEST['lessequal_ondate']?>&now_extender=<?echo $_REQUEST['now_extender']?>" >
                <i class="layui-icon">&#xe62d;</i> 导出所有学校数据</a>

        </div>







        <br class="clearfloat"/>
    </form>


</div>
    <blockquote class="layui-elem-quote">
        <div>需要所有学校数据，请直接导出excel。由于所有数据均为实时计算，需要消耗一定时间。</div>
        <div>本表格用于配送，<a href="order-pepare-statistic.php?now_extender=order"  style="color:red;">盘点</a>仅需要产品数量的可以查看<a href="order-pepare-statistic.php?now_extender=order" style="color:red;">备货统计</a></div>
        <div>旧订单会以退款日期作为退款申请日期，<b>取消次日的配送</b>,配送日期为支付日期次日起算(T+1)</div>
    </blockquote>



 <hr/>


<table class="layui-table">
    <thead>
    <tr>
        <th>学校</th>
        <th>数量</th>
        <th>日期</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <?foreach ($school_list as $k=>$v){?>
    <tr>
        <td><?echo $v['name']?></td>
 <?//print_r2($detail[$v['name']]);    ?>

        <td> <?
                $parameter['key']='status';//需要统计的键值
                $parameter['value']='正常';//需要统计
                echo $shcool_sum[]=count_sum_with_key_in_2d_array($detail[$v['name']],$parameter);?>
        </td>
        <td>
        <?echo $_REQUEST['greaterequal_ondate']?> 至
        <?echo $_REQUEST['lessequal_ondate']?>
        </td>
        <td>
            <a class="layui-btn white layui-btn-sm" target="_blank"
               href="export.php?school=<?echo $v['name']?>&greaterequal_ondate=<?echo $_REQUEST['greaterequal_ondate']?>&lessequal_ondate=<?echo $_REQUEST['lessequal_ondate']?>&now_extender=<?echo $_REQUEST['now_extender']?>" >
                <i class="layui-icon">&#xe62d;</i> 导出</a>
        </td>
    </tr>
    <?}?>
    <tr>
        <td>合计</td>
        <td colspan="4">
            <?
//                $p['item']="order_id";
//                $p['table']=$table_prefix."order_info";
//                $p['condition']="startdate <=  '{$indate} 00:00:00'   and
//                              enddate >=  '{$indate} 00:00:00'  and
//                              add_date < '{$indate}  00:00:00' and
//                              (status !='已删除' or status is null) and
//                              pay_status = 1";
//
//                $result=count_number($p);
//               echo $result[0];

                echo $shcool_sum_total=array_sum($shcool_sum);
                ?>
        </td>
    </tr>
    </tbody>
</table>






<!--    列出不同学校，不同班级的统计，然后有个导出-->
<table  class="layui-table">
    <thead>

    </thead>
    <tbody>




<?foreach ($school_list as $k=>$v){

        if($_REQUEST['school'] == $v['name']){

        ?>
    <tr><td  colspan="<?echo count_days($greater_startdate,$less_enddate)+7?>" style="text-align: center"><h1><?echo $v['name']?></h1></td></tr>
    <tr><td  colspan="<?echo count_days($greater_startdate,$less_enddate)+7?>" style="text-align: right">
            日期 : <?echo $_REQUEST['greaterequal_ondate']?> 至
            <?echo $_REQUEST['lessequal_ondate']?>
        </td></tr>

        <tr></tr>




<!--    开始循环这个学校的年级-->
    <?foreach ($v[$v['name']] as $k2=>$v2){?>
<!--        <h2><b>--><?//echo $v2['name'];?><!--</b></h2>-->

        <!--    开始循环这个年级的班-->
        <?foreach ($v2[$v2['name']] as $k3=>$v3){?>
<!--            <h3>--><?//echo $v3['name'];?><!--</h3>-->

            <tr>
                <th>序号</th>
                <th>班别</th>
                <th>姓名</th>
                <? //循环开始日期到结束日期 从$_REQUEST['greaterequal_ondate'] 直到 $_REQUEST['lessequal_ondate']
                    for($i=strtotime($_REQUEST['greaterequal_ondate']);$i<=strtotime($_REQUEST['lessequal_ondate']);$i+=86400){
                        $date = date("Y-m-d",$i);
                        ?>
                        <th><?echo substr($date,5)?><br/><?echo $week_map[date("w", strtotime($date))];
                            ?></th>
                    <?}
                     ?>

                <th>签收</th>
                <th>备注</th>
                <th>期末补发</th>

            </tr>

                <? //每个班开始，重置一下 统计，
                   $class_sum=[]?>
                <? $student_list = select_lines_items($table_prefix."order_detail",
                "name asc","name,order_name,student_nid",
                    "school = '{$v['name']}' and
                              grade = '{$v2['name']}' and
                              status = '正常' and
                              class_ = '{$v3['name']}' and ondate in ('{$day_period}')
                              group by student_nid 
                              ","");?>


                <? foreach ($student_list as $k4=>$v4){?>

                <? //查一下这个学生的名字的订单
                    $ond_student_list = select_lines_items($table_prefix."order_detail",
                    "name asc","name,ondate,product_name,order_name,status",
                    "school = '{$v['name']}' and
                              grade = '{$v2['name']}' and
                              class_ = '{$v3['name']}' and 
                              student_nid = '{$v4['student_nid']}' and 
                              status = '正常' and
                              ondate in ('{$day_period}')
                              ","");
                    $class_sum[]=count($ond_student_list);
                ?>


                        <tr>
                            <td><?echo $k4+1?> </td>
                            <td><b><?echo $v2['name'];?> <?echo $v3['name'];?></b></td>
                            <td ><?echo $v4['name']?></td>
                            <? //循环开始日期到结束日期 从$_REQUEST['greaterequal_ondate'] 直到 $_REQUEST['lessequal_ondate']
                                for($i=strtotime($_REQUEST['greaterequal_ondate']);$i<=strtotime($_REQUEST['lessequal_ondate']);$i+=86400){
                                    $date = date("Y-m-d",$i); ?>
                             <td>
                                 <?foreach ($ond_student_list as $k5=>$v5){?>
                                     <?if($v5['ondate'] == $date." 00:00:00"){?>
                                         <?echo $v5['product_name'];?>
                                     <?}?>
                                     <?;}?>
                             </td>
                                <?} ?>
                            <td></td>
                            <td><?echo $v4['order_name'];?></td>
                            <td></td>

                        </tr>

                    <?;}?>


            <? if(!count($student_list)){?>
                <tr>
                <td colspan="<?echo count_days($greater_startdate,$less_enddate)+7?>"><b><?echo $v2['name'];?> <?echo $v3['name'];?></b> 暂无订单</td>



                </tr>
                <?;}?>


<!--            <tr>-->
<!--                <td> </td>-->
<!--                <td></td>-->
<!--                <td > 小计 </td>-->
<!--                --><?// //循环开始日期到结束日期 从$_REQUEST['greaterequal_ondate'] 直到 $_REQUEST['lessequal_ondate']
//                    for($i=strtotime($_REQUEST['greaterequal_ondate']);$i<=strtotime($_REQUEST['lessequal_ondate']);$i+=86400){
//                        $date = date("Y-m-d",$i); ?>
<!--                        <td>-->
<!--                            --><?//foreach ($ond_student_list as $k5=>$v5){?>
<!--                                --><?//if($v5['ondate'] == $date." 00:00:00"){?>
<!--                                    --><?//echo count($ond_student_list);?>
<!--                                --><?//}?>
<!--                                --><?//;}?>
<!--                        </td>-->
<!--                    --><?//} ?>
<!--                <td></td>-->
<!--                <td>--><?//echo $v4['order_name'];?><!--</td>-->
<!--            </tr>-->

            <tr>
                <td colspan="<?echo count_days($greater_startdate,$less_enddate)+7?>">
<!--                    本日统计 ： --><?// echo count($student_list)?><!--  /  -->
                    本周统计 ： <? echo array_sum($class_sum)?>
                </td>
            </tr>
            <tr>
            </tr>

        <?}?>

    <?}?>
<?}?>
<?}?>
    </tbody>
</table>




</div>
</div>

<!--content端點01-->
</div>
<!--maincontent端點01-->
<br class="clearfloat"/>
</div>
<!--container端點01-->
</div>


<?php include ROOT_PATH_ . "/controller/common/module/footer.php"; ?>



</body>



</html>
